package 练习;

import java.util.Scanner;

/**
 * Copyright (C) 2023 思创数码科技股份有限公司
 * <p/>
 * 版权所有
 * <p/>
 * 类名　　  : Test2
 * 功能概要  :
 *
 * @author yangwk
 * @date 2024/5/31 22:47
 */
public class Test2 {
    public static int  find(String str,String target){
        if (str.length() > target.length()) {
            return -1;
        }
        if (str.length() == 0 && target.length() == 0) {
            return 0;
        }
        if (str.length() == 0 && target.length() != 0) {
            return 0;
        }
        if (str.length() != 0 && target.length() == 0) {
            return -1;
        }
        int[][] dp = new int[str.length() + 1][target.length() + 1];
        for (int i = 1; i <= str.length(); i++) {
            for (int j = 1; j <= target.length(); j++) {
                if (str.charAt(i-1) == target.charAt(j-1)) {
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                }else{
                    dp[i][j] = Math.max(dp[i][j - 1], dp[i - 1][j]);
                }
            }
        }
        boolean find = dp[str.length()][target.length()] == str.length();
        if(find){
            int length = str.length();
            for (int i = 1; i <= str.length(); i++) {
                for (int j = 1; j <= target.length(); j++) {
                    if (dp[i][j] == length) {
                        return j-1;
                    }
                }
            }
        }
        return -1;
    }
    public static void main(String[] args) {
//        Scanner in = new Scanner(System.in);
//        String s1 = in.nextLine();
//        String s2 = in.nextLine();
////        System.out.println(find(s1, s2));
        System.out.println(find("", "abcdecc"));

    }
}
